package com.zhongkai.controller;

import com.zhongkai.app.service.BigInTimeService;
import com.zhongkai.model.utils.ZhongkaiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

@Controller
public class BigInTimeController {

    @Autowired
    private BigInTimeService bigInTimeService;


    /**
     * 设备异常记录
     *
     * @param unit_uuid 设备uuid
     * @param page      当前页数
     * @param rows      每页数据条数
     */
    @RequestMapping(value = "/big_date/list", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult getUserRecord(
            String unit_uuid, @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows

    ) {


        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = bigInTimeService.getUserRecord(
                    unit_uuid
                    , page
                    , rows
            );
        } catch (Exception e) {
            e.printStackTrace();
            return ZhongkaiResult.build(405, "查询失败");
        }

        return zhongkaiResult;
    }


    /**
     * 获取设备列表
     *
     * @param page   当前页数
     * @param rows   每页数据条数
     * @param status 类型 1 正常设备 2异常设备 3全部设备 4维修设备
     */
    @RequestMapping(value = "/big_date/user_all", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult getUserAll(
            @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows,
            @RequestParam(defaultValue = "0") Integer status

    ) {


        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = bigInTimeService.getUserAll(
                    page
                    , rows, status

            );
        } catch (Exception e) {
            e.printStackTrace();
            return ZhongkaiResult.build(405, "查询失败");
        }

        return zhongkaiResult;
    }

    /**
     * 获取设备列表
     *
     * @param uuid   设备uuid
     */
    @RequestMapping(value = "/big_date/current", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult getCurrent(
String uuid
    ) {


        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = bigInTimeService.getCurrent(
                    uuid

            );
        } catch (Exception e) {
            e.printStackTrace();
            return ZhongkaiResult.build(405, "查询失败");
        }

        return zhongkaiResult;
    }


    /**
     * 获取所有设备数量统计
     */
    @RequestMapping(value = "/big_date/unit_count", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult getUnitCount(


    ) {


        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = bigInTimeService.getUnitCount(

            );
        } catch (Exception e) {
            e.printStackTrace();
            return ZhongkaiResult.build(405, "查询失败");
        }

        return zhongkaiResult;
    }


    /**
     * 获取单台设备的实时数据
     *
     * @param unit_uuid 设备uuid
     */
    @RequestMapping(value = "/big_date/unit_in", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult getUserInTime(
            String unit_uuid

    ) {


        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = bigInTimeService.getUserInTime(

                    unit_uuid
            );
        } catch (IOException e) {
            e.printStackTrace();
            return ZhongkaiResult.build(400, "解析失败");
        }

        return zhongkaiResult;
    }


    /**
     * 根据用户uuid获取用户下全部设备
     *
     * @param user_uuid   用户uuid
     */
    @RequestMapping(value = "/big_date/user_sum_unit", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult getUserUnitSum(
            String user_uuid

    ) {


        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = bigInTimeService.getUserUnitSum(user_uuid);
        } catch (Exception e) {
            e.printStackTrace();
            return ZhongkaiResult.build(400, "解析失败");
        }

        return zhongkaiResult;
    }





    /**
     * 根据用户名获取用户下全部设备
     *
     * @param user_name   模糊的用户名
     */
    @RequestMapping(value = "/big_date/like_name", produces = "application/json;charset=utf-8")
    @ResponseBody
    public ZhongkaiResult likeName(
            String user_name, @RequestParam(defaultValue = "0") Integer page, @RequestParam(defaultValue = "0") Integer rows

    ) {


        ZhongkaiResult zhongkaiResult = null;
        try {
            zhongkaiResult = bigInTimeService.likeName(user_name,page,rows);
        } catch (Exception e) {
            e.printStackTrace();
            return ZhongkaiResult.build(400, "解析失败");
        }

        return zhongkaiResult;
    }
}
